<template>
  <view class="chart_senv">
    <mk-echart :options="options" :key="key"></mk-echart>
  </view>
</template>

<script>
import MkEchart from "../../libs/index.vue";
export default {
  name: "chartSeven",
  components: {
    MkEchart,
  },
  props: {
    xData: {
      // x轴数据
      type: Array,
      default: () => [],
    },
    maxVal: {
      type: Number,
      default: 10
    }
  },
  watch: {
    xData: {
      deep: true,
      handler(val) {
        this.options.xAxis.data = val;
        this.$nextTick(() => {
          this.key = new Date().getTime();
        });
      },
    },
    maxVal: {
      immediate: true,
      handler() {
        this.setOptions();
        console.log(this.options)
      },
    },
  },
  data() {
    return {
      key: new Date().getTime(),
      val: 0,
      options: {},
    };
  },
  created() {
    this.setOptions();
  },
  mounted() {
    this.setOptions();
  },
  methods: {
    setOptions() {
      let options = {
        angleAxis: {
          startAngle: 260,
          max: this.maxVal,
          clockwise: false, // 顺时针
          // 隐藏刻度线
          show: false,
        },
        radiusAxis: {
          type: "category",
          show: true,
          axisLabel: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        polar: {
          center: ["28%", "-402%"],
          radius: "1980%", //图形大小
        },
        series: [
          {
            stack: "测试",
            type: "bar",
            data: [100],
            coordinateSystem: "polar",
            barWidth: 10,
            silent: true,
            roundCap: true,
            itemStyle: {
              normal: {
                opacity: 1,
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#D02E2E", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#FFB1B1", // 100% 处的颜色
                    },
                  ],
                  global: false, // 缺省为 false
                },
                borderWidth: 3,
              },
            },
          },
          {
            z: 100,
            stack: "测试",
            type: "bar",
            data: [0.01],
            coordinateSystem: "polar",
            roundCap: true,
            itemStyle: {
              color: "#fff",
              borderColor: "#D12F2F",
              borderWidth: 5,
            },
          },
          {
            z: 2,
            stack: "测试",
            type: "bar",
            data: [10],
            coordinateSystem: "polar",
            silent: true,
            roundCap: true,
            itemStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                colorStops: [
                  {
                    offset: 0,
                    color: "#CFD3DF", // 0% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "#CFD3DF", // 100% 处的颜色
                  },
                ],
              },
              borderColor: "#CFD3DF",
              borderWidth: 0,
            },
          },
        ],
      };
      this.options = options;
    },
  },
};
</script>

<style>
.chart_senv {
  width: 700rpx;
  height: 200rpx;
  /* border: 1px solid #ccc; */
}
</style>
